<template>
	<view>
		<view class="search-box">
			<!-- <my-search @click="gotoSearch" :bgcolor="'#ab9d7e'" :redius="2"></my-search>自定义组件属性 -->
			<my-search @click="gotoSearch" class="search-box"></my-search>
		</view>
		<!-- 轮播区 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="1000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<!-- <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id"> -->
				<navigator class="swiper-item" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航区 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandker(item)">
				<image :src="item.image_src"></image>
			</view>
		</view>
		<!-- 楼层区 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image :src="item.floor_title.image_src" class="floor-title"></image>
				<view class="floor-img-box">
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src"
							:style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="right-img-box">
						<navigator class="right-img-item" v-for="(item2,index2) in item.product_list" :key="index2"
							v-if="index2 !== 0" :url="item2.url">
							<image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width + 'rpx'}">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				swiperList: [], //轮播图列表
				navList: [], //分类导航数据列表
				floorList: [] //楼层数据
			};
		},
		// uniapp的初始化生命周期
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			gotoSearch() {
				uni.navigateTo({
					url: "../../subpkg/search/search"
				})
			},
			// 获取轮播
			async getSwiperList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if (res.meta.status !== 200) {
					uni.$showMsg()
				} else {
					this.swiperList = res.message
					uni.$showMsg('数据请求成功')
					console.log('1.轮播图数据列表', res)
				}
			},
			// 获取分类列表
			async getNavList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/catitems')
				if (res.meta.status !== 200) {
					uni.$showMsg()
				} else {
					this.navList = res.message
					console.log('2.分类导航的数据', res.message);
				}
			},
			// 分类跳转
			navClickHandker(item) {
				console.log('3.判断点击的是那个分类', item);
				if (item.name === '分类') {
					uni.switchTab({
						url: '../classify/classify'
					})
				}
				if (item.name === '秒杀拍') {
					uni.switchTab({
						url: '../cart/cart'
					})
				}
				if (item.name === '超市购') {
					uni.switchTab({
						url: '../my/my'
					})
				}
				if (item.name === '母婴品') {
					uni.switchTab({
						url: '../cart/cart'
					})
				}
			},
			// 获取楼层数据
			async getFloorList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/floordata')
				if (res.meta.status !== 200) {
					uni.$showMsg()
				} else {
					this.floorList = res.message
					res.message.forEach(floor => {
						floor.product_list.forEach(prod => {
							prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split(
								'?')[1]
						})
					})
					console.log('4.楼层数据', res);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search-box {
		position: sticky;
		top: 0px;
		z-index: 9;
	}

	swiper {
		height: 25vh;

		.swiper-item,
		image {
			height: 100%;
			width: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;


		padding: 10px 0;

		.nav-item {
			width: 20vw;
			height: 20vw;

			image {
				width: 20vw;
				height: 20vw;
			}
		}
	}

	.floor-title {
		width: 100%;
		height: 60rpx;
	}

	.floor-img-box {
		display: flex;
		justify-content: space-evenly;
		padding-left: 10rpx;

		.left-img-box {
			width: 30vw;
		}

		.right-img-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
			align-items: center;
		}
	}
</style>
